<?php

namespace EM\NewsBundle\Entity;

use Doctrine\ORM\EntityRepository;

class GeographyRepository extends EntityRepository
{
    /**
     * Set geographies
     *
     * @param integer $author
     * @return EntityRepository
     */
    public function findByGeoAuthorPermissions($author)
    {
        return $this->getEntityManager()
            ->createQuery(
                'SELECT g.id, g.name FROM EMNewsBundle:Geography g, EMNewsBundle:UserGeoLangSettings s, EMNewsBundle:GeoLangRelation r WHERE s.user=:id and g.id=r.geo and s.geoLang=r.id group by g.id order by g.name asc'
            )->setParameter('id', $author)
            ->getResult();
    }
}